<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="Responsive Admin &amp; Dashboard Template based on Bootstrap 5">
    <meta name="author" content="AdminKit">
    <meta name="keywords" content="adminkit, bootstrap, bootstrap 5, admin, dashboard, template, responsive, css, sass, html, theme, front-end, ui kit, web">

    <script src="js/jquery-3.2.1.js"></script>

    <script src="js/js.cookie.js"></script>
    <link rel="preconnect" href="https://fonts.gstatic.com">
    <link rel="shortcut icon" href="img/icons/icon-48x48.png" />

    <link rel="canonical" href="https://demo-basic.adminkit.io/pages-sign-in.html" />

    <title>登录</title>
    <link rel="stylesheet" href="https://unpkg.com/@adminkit/core@latest/dist/css/app.css">
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600&display=swap" rel="stylesheet">
</head>

<body>
<main class="d-flex w-100">
    <div class="container d-flex flex-column">
        <div class="row vh-100">
            <div class="col-sm-10 col-md-8 col-lg-6 mx-auto d-table h-100">
                <div class="d-table-cell align-middle">

                    <div class="text-center mt-4">
                        <h1 class="h2" >欢 迎 来 到 在 线 考 试 系 统</h1>
                        <p class="lead">
                            请输入您的账号
                        </p>
                    </div>

                    <div class="card">
                        <div class="card-body">
                            <div class="m-sm-4">

                                <div class="form-group">
                                    <label for="usermail" class="form-label">邮箱</label>
                                    <input type="text" class="form-control form-control-lg" id="usermail" placeholder="请输入邮箱">
                                </div>
                                <div class="form-group">
                                    <label for="password" class="form-label">密码</label>
                                    <input type="password" class="form-control form-control-lg" id="password" placeholder="请输入密码">
                                </div>
                                <div class="checkbox text-left">

                                    <label class="form-check">
                                        <input class="form-check-input" type="checkbox" value="remember">
                                        <span class="form-check-label">
												记住密码
											</span>
                                    </label>
                                </div>


                                <p style="text-align: right;color: red;position: absolute" id="info"></p><br/>

                                <div class="text-center mt-3">
                                    <button id="loginButton"  class="btn btn-lg btn-primary">登录
                                    </button>
                                    <a href="register" class="panel-title">请注册</a>


                                </div>



                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</main>

<script src="https://unpkg.com/@adminkit/core@latest/dist/js/app.js"></script>
<script>

    // 记住登录信息
    function rememberLogin(usermail, password, checked) {
        Cookies.set('loginStatus', {
            usermail: usermail,
            password: password,
            remember: checked
        }, {expires: 30, path: ''})
    }
    // 若选择记住登录信息，则进入页面时设置登录信息
    function setLoginStatus() {
        var loginStatusText = Cookies.get('loginStatus')
        if (loginStatusText) {
            var loginStatus
            try {
                loginStatus = JSON.parse(loginStatusText);
                $('#usermail').val(loginStatus.usermail);
                $('#password').val(loginStatus.password);
                $("#remember").prop('checked',true);
            } catch (__) {}
        }
    }

    // 设置登录信息
    setLoginStatus();//点击登录后
    $("#loginButton").click(function () {
        var usermail =$("#usermail").val();

        var password=$("#password").val();
        var remember=$("#remember").prop('checked');
        if (usermail == '') {
            $("#info").text("提示:账号不能为空");
        }
        else if( password ==''){
            $("#info").text("提示:密码不能为空");
        }

        else {

            $.ajax({
                type: "POST",
                url: "logincheck",
                data: {
                    usermail: usermail,
                    password: password
                },
                dataType: "json",
                success: function(data) {
                    if (data.type.trim() === "404") {
                        alert("提示:账号或密码错误！");
                    } else if (data.type.trim() === "0") {
                        if(remember){
                            rememberLogin(usermail,password,remember);
                        }else {
                            Cookies.remove('loginStatus');
                        }
                        alert("提示:登陆成功，跳转中...");
                        window.parent.location.href = "teacher.html";

                    } else if (data.type.trim() === "1") {
                        if(remember){
                            rememberLogin(usermail,password,remember);
                        }else {
                            Cookies.remove('loginStatus');
                        }
                        alert("提示:登陆成功，跳转中...");
                        window.parent.location.href = "/personpage3";

                    }
                    else if (data.type.trim() === "2") {
                        if(remember){
                            rememberLogin(usermail,password,remember);
                        }else {
                            Cookies.remove('loginStatus');
                        }
                        alert("提示:登陆成功，跳转中...");
                        window.parent.location.href = "admin.html";

                    }
                }
            });
        }
    })

</script>
</body>

</html>